import { createSlice } from "@reduxjs/toolkit";
import { persistReducer } from 'redux-persist';
import storage from 'redux-persist/lib/storage';

export const userInfoSlice = createSlice({
  name: "userInfo",
  initialState: {
    nickName: '',
    avatorUrl: '',
    token: '',
    company: '',
    groupName: '',
    groupAvatarUrl: '',
    roleType:'',
    ticket: 0
  },
  reducers: {
    setUserInfo: (state, action) => {
      const {nickName, avatar, token, roleType, company, ticket} = action.payload;
      state.nickName = nickName;
      state.company = company;
      state.avatorUrl = avatar;
      state.token = token;
      state.roleType = roleType;
      state.ticket = ticket;
    },


    clearUserInfo: (state,atcion) => {
      state.nickName= '';
      state.avatorUrl=  '';
      state.token= '';
      state.company= '';
      state.groupName=  '';
      state.groupAvatarUrl=  '';
      state.roleType= '';
      state.ticket=  0;
      console.log(`clearUserInfo ${state}`)
    },
  }
});

export const { setUserInfo,clearUserInfo } = userInfoSlice.actions;
export default userInfoSlice.reducer;